home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Programming Utilities / MPW Extras ƒ / Scripts / NewOpenSelection < prev    next >
Encoding:
Text File  |  1991-08-29  |  3.0 KB  |  75 lines  |  [TEXT/ttxt]

  1. # NewOpenSelection - replacement "Open Selection" script supporting file searching, backup and remember
  2.  
  3. Set ScriptName "{0}"                                                                        # save the script's name
  4. Set FileName "`TypeFile -q "{Active}".§ ≥≥ Dev:Null`"
  5. If ({FileName} != "")
  6.     Open "{FileName}" ∑∑ Dev:Null
  7.     Set OpenStatus {Status}
  8.     If ({OpenStatus} == 0)
  9.         # the Open was successful - perform the backup and remember chores
  10.         ReadOnlyStatus "{Active}" ∑∑ Dev:Null                                                # test if this is a read-only file
  11.         If ({Status} == 0)
  12.             Set LeafName "`ParseFileName -l "{Active}"`"                                    # get the file's leafname
  13.             Duplicate -y "{Active}" "{Backup}" ∑∑ "{Worksheet}" || Beep                        # create the backup file
  14.     
  15.             # Delete all the old "Remember" backup files
  16.             For i in `Begin; Files -f "{Backup}{LeafName}".[0-9]+; End ≥ Dev:Null`
  17.                 Delete "{i}"
  18.             End  # For i
  19.         End  # If {OpenStatus}
  20.     Else
  21.         If ({OpenStatus} == 2)
  22.             # the file was not found in the current directory:  search for matching files
  23.             Set FileName "`TypeFile -q "{Active}".§ ≥≥ Dev:Null`"
  24.             Set FoundAny 0                                                                    # initialize
  25.             Delete NewOpenSelection.temp ∑∑ Dev:Null
  26.             If (("{#}" == 1) && ("{1}" == "-a"))
  27.                 # perform an all-colume search
  28.                 For i in `Volumes ≥≥ Dev:Null`
  29.                     WhereIs -c -s "{i}" {FileName} >> NewOpenSelection.temp ≥≥ Dev:Null
  30.                     If ({Status} == 0)
  31.                         Set FoundAny 1                                                        # signal that at least one match was found
  32.                     End  # If {Status}
  33.                 End  # For i
  34.             Else
  35.                 # search only MPW volume
  36.                 Set i `Volumes "{MPW}" ≥≥ Dev:Null`
  37.                 WhereIs -c -s "{i}" {FileName} >> NewOpenSelection.temp ≥≥ Dev:Null
  38.                 If ({Status} == 0)
  39.                     Set FoundAny 1                                                            # signal that at least one match was found
  40.                 End  # If {Status}
  41.             End  # If {#}
  42.             If ({FoundAny})
  43.                 Set SelName `Begin; GetListItem -m "Open which file:" -s < NewOpenSelection.temp; Set ListStatus {Status}; End` ≥≥ Dev:Null
  44.                 Delete NewOpenSelection.temp ∑∑ Dev:Null
  45.                 If ({ListStatus} == 0)
  46.                     Open {SelName} ∑∑ Dev:Null
  47.                     Set OpenStatus {Status}
  48.                     If ({OpenStatus} == 0)
  49.                         # the Open was successful - perform the backup and remember chores
  50.                         ReadOnlyStatus "{Active}" ∑∑ Dev:Null                                # test if this is a read-only file
  51.                         If ({Status} == 0)
  52.                             Set LeafName "`ParseFileName -l "{Active}"`"                    # get the file's leafname
  53.                             Duplicate -y "{Active}" "{Backup}" ∑∑ "{Worksheet}" || Beep        # create the backup file
  54.                     
  55.                             # Delete all the old "Remember" backup files
  56.                             For i in `Begin; Files -f "{Backup}{LeafName}".[0-9]+; End ≥ Dev:Null`
  57.                                 Delete "{i}"
  58.                             End  # For i
  59.                         End  # If {Status}
  60.                     Else
  61.                         Alert "{ScriptName}:∂nUnable to open file {SelName}."
  62.                     End  # If {OpenStatus}
  63.                 End  # If {ListStatus}
  64.             Else
  65.                 Alert "{ScriptName}:∂nNo files matching {FileName} were found."
  66.             End  # If FoundAny
  67.         Else
  68.             Alert "{ScriptName}:∂nUnable to open file {FileName}."
  69.         End  # If {OpenStatus}
  70.     End  # If {OpenStatus}
  71. Else
  72.     Alert "{ScriptName}:∂nThere is no selection"
  73. End  # If {FileName}
  74.  
  75. # end of NewOpenSelection